import { contextBridge, ipcRenderer } from "electron";

window.ipcRenderer = {
  send: (channel, data) => {
    ipcRenderer.send(channel, data)
  },
  on: (channel, callback) => {
    ipcRenderer.on(channel, (event, ...args) => callback(...args))
  },
  invoke:(channel, data)=>{
  	  ipcRenderer.invoke(channel, data)
  },
}

contextBridge.exposeInMainWorld('wxWindow', {
	update:()=> ipcRenderer.invoke('wx:windowStatus:update'),
	minimize:()=> ipcRenderer.invoke('wx:windowStatus:minimize'),
	maximize:()=> ipcRenderer.invoke('wx:windowStatus:maximize'),
	unmaximize:()=> ipcRenderer.invoke('wx:windowStatus:unmaximize'),
	closeWindow:()=> ipcRenderer.invoke('wx:windowStatus:closeWindow'),
	closeChildWindow:()=> ipcRenderer.invoke('wx:windowStatus:closeChildWindow'),
	alwaysOnTop:(data)=> ipcRenderer.invoke('wx:windowStatus:alwaysOnTop',data),
	showmenu:(data)=> ipcRenderer.invoke('wx:windowStatus:showmenu',data),
	download:(url)=> ipcRenderer.invoke('wx:windowStatus:download',url),
	createWin:(data)=> ipcRenderer.invoke('wx:windowStatus:createWin',data),
	windowdrag:(data)=> ipcRenderer.invoke('wx:windowStatus:windowdrag',data),
	receiveMessageFromMain: (callback) => { //从主进程发给渲染进程,渲染进程接收消息事件
		ipcRenderer.on("wx:windowStatus:changed", (event, message) => {
			callback(message);
		});
		ipcRenderer.on("download-item-updated", (event, message) => {
			callback(message);
		});
		ipcRenderer.on("download-item-done", (event, message) => {
			callback(message);
		});
		ipcRenderer.on("fullScreen", (event, message) => {
			callback(message);
		});
		ipcRenderer.on("recordScreen", (event, message) => {
			callback(message);
		});
		ipcRenderer.on("openDevtools", (event, message) => {
			callback(message);
		});
	},
});